package com.ruihu.admin.module.business.task.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruihu.admin.common.anno.MethodLog;
import com.ruihu.admin.common.domain.PageResultDTO;
import com.ruihu.admin.common.domain.ResponseDTO;
import com.ruihu.admin.module.business.task.converter.TaskNodeInstList;
import com.ruihu.admin.module.business.task.dao.TaskNodeInstDao;
import com.ruihu.admin.module.business.task.domain.dto.TaskNodeInstAddDTO;
import com.ruihu.admin.module.business.task.domain.dto.TaskNodeInstDTO;
import com.ruihu.admin.module.business.task.domain.dto.TaskNodeInstQueryDTO;
import com.ruihu.admin.module.business.task.domain.dto.TaskNodeInstUpdateDTO;
import com.ruihu.admin.module.business.task.domain.entity.TaskNodeInstEntity;
import com.ruihu.admin.module.business.task.domain.vo.TaskNodeInstExcelVO;
import com.ruihu.admin.module.business.task.domain.vo.TaskNodeInstVO;
import com.ruihu.admin.util.BeanUtil;
import com.ruihu.admin.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * [ 任务环节实例表 ]
 *
 * @author Tony
 * @version 1.0
 * @company 瑞虎（南京）信息技术有限公司
 * @copyright (c)  瑞虎（南京）信息技术有限公司Inc. All rights reserved.
 * @date 2022-08-30 17:01:07
 * @since JDK1.8
 */
@Service
public class TaskNodeInstService {

    @Autowired
    private TaskNodeInstDao taskNodeInstDao;

    /**
     * 根据id查询
     */
    public TaskNodeInstEntity getById(Long id){
        return  taskNodeInstDao.selectById(id);
    }

    /**
     * 分页查询
     * @author Tony
     * @date 2022-08-30 17:01:07
     */
    @MethodLog
    public ResponseDTO<PageResultDTO<TaskNodeInstVO>> queryByPage(TaskNodeInstQueryDTO queryDTO) {
        Page page = PageUtil.convert2QueryPage(queryDTO);
        List<TaskNodeInstDTO> taskNodeInstDTOList = taskNodeInstDao.queryByPage(page, queryDTO);
        List<TaskNodeInstVO> taskNodeInstVOList = TaskNodeInstList.convertDTOToTaskNodeInstVOList(taskNodeInstDTOList);
        page.setRecords(taskNodeInstVOList);
        PageResultDTO<TaskNodeInstVO> pageResultDTO = PageUtil.convert2PageResult(page);
        return ResponseDTO.succData(pageResultDTO);
    }

    /**
     * 不分页查询
     * @param queryDTO
     * @return
     */
    @MethodLog
    public ResponseDTO<List<TaskNodeInstVO>> queryByList(TaskNodeInstQueryDTO queryDTO) {
        List<TaskNodeInstEntity> taskNodeInstEntityList = taskNodeInstDao.queryList(queryDTO);
        List<TaskNodeInstVO> voList = TaskNodeInstList.convertEntityToTaskNodeInstVOList(taskNodeInstEntityList);
        return ResponseDTO.succData(voList);
    }

    /**
     * 添加
     * @author Tony
     * @date 2022-08-30 17:01:07
     */
    @MethodLog
    public ResponseDTO<String> add(TaskNodeInstAddDTO addDTO) {
        TaskNodeInstEntity entity = BeanUtil.copy(addDTO, TaskNodeInstEntity.class);
        taskNodeInstDao.insert(entity);
        return ResponseDTO.succ();
    }

    /**
     * 编辑
     * @author Tony
     * @date 2022-08-30 17:01:07
     */
    @MethodLog
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> update(TaskNodeInstUpdateDTO updateDTO) {
        TaskNodeInstEntity entity = BeanUtil.copy(updateDTO, TaskNodeInstEntity.class);
        taskNodeInstDao.updateByIdIgnoreEmptyValue(entity);
        return ResponseDTO.succ();
    }

    /**
     * 删除
     * @author Tony
     * @date 2022-08-30 17:01:07
     */
    @MethodLog
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> deleteByIds(List<Long> idList) {
        taskNodeInstDao.deleteByIdList(idList);
        return ResponseDTO.succ();
    }

    /**
     * 查询全部导出对象
     * @author Tony
     * @date 2022-08-30 17:01:07
     */
    @MethodLog
    public List<TaskNodeInstExcelVO> queryAllExportData(TaskNodeInstQueryDTO queryDTO) {
        return taskNodeInstDao.queryAllExportData( queryDTO);
    }

    /**
     * 批量查询导出对象
     * @author Tony
     * @date 2022-08-30 17:01:07
     */
    @MethodLog
    public List<TaskNodeInstExcelVO> queryBatchExportData(List<Long> idList) {
        return taskNodeInstDao.queryBatchExportData(idList);
    }
}
